import java.util.Scanner;

public class Demo15 {
    static String[] work = new String[4];

    static int[] reqCapacity = new int[4];

    static int[] runTime = new int[4];

    static int[] priorityNumber = new int[4];

    static boolean[] isMemory = new boolean[4];

    static boolean[] isRun = new boolean[4];

    public static int fit(){
        //找出装入内存的值
        int max = Integer.MIN_VALUE;
        int index = 0;
        for(int i = 1; i <= 3; i++){
            if(!isMemory[i] && priorityNumber[i] > max){
                max = priorityNumber[i];
                index = i;
            }
        }
        return index;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        for(int i = 1; i <= 3; i++){
            work[i] = scan.next();
            reqCapacity[i] = scan.nextInt();
            runTime[i] = scan.nextInt();
            priorityNumber[i] = scan.nextInt();
        }
        int index = fit();
        isMemory[index] = true;
        int size = reqCapacity[index];
        int temp3 = 0;
        for(int i = 1; i <= 3; i++){
            if(i != index && i != fit()){
                temp3 = i;
            }
        }
        if(reqCapacity[fit()] + size < 100){
            int index1 = fit();
            isMemory[index1] = true;
            size += reqCapacity[index1];
            if(reqCapacity[fit()] + size < 100){
                int index2 = fit();
                isMemory[index2] = true;
                size += reqCapacity[index2];

            }
        }else if(reqCapacity[temp3] + size < 100){
            int index1 = temp3;
            isMemory[index1] = true;
            size += reqCapacity[index1];
            if(reqCapacity[fit()] + size < 100){
                int index2 = fit();
                isMemory[index2] = true;
                size += reqCapacity[index2];

            }
        }
        int max1 = Integer.MIN_VALUE;
        int maxIndex1 = 0;
        int min1 = Integer.MAX_VALUE;
        int minIndex1 = 0;
        int midIndex1 = 0;
        for(int i = 1; i <= 3; i++){
            if(runTime[i] < min1){
                min1 = runTime[i];
                minIndex1 = i;
            }
            if(runTime[i] >= max1){
                max1 = runTime[i];
                maxIndex1 = i;
            }
        }
        for(int i = 1; i <= 3; i++){
            if(i != minIndex1 && i != maxIndex1){
                midIndex1 = i;
            }
        }
        int one = 0;
        int left = 0;
        int right = 0;
        if(isMemory[minIndex1]){
            one = minIndex1;
            left = midIndex1;
            right = maxIndex1;
        }else if(isMemory[midIndex1]){
            one = midIndex1;
            left = minIndex1;
            right = maxIndex1;
        }else{
            one = maxIndex1;
            left = minIndex1;
            right = midIndex1;
        }
        System.out.println(work[one]);


        int size1 = reqCapacity[left] + reqCapacity[right];

        if(size1 <= 100){
            System.out.println(work[left]);
            System.out.println(work[right]);
        }else{
            if(priorityNumber[left] < priorityNumber[right]){
                System.out.println(work[right]);
                System.out.println(work[left]);
            }else{
                System.out.println(work[left]);
                System.out.println(work[right]);
            }
        }


    }
}
